package com.witmore.skyline.web.config;

import com.witmore.skyline.web.filter.AccessTokenAuthenticationFilter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.filter.OncePerRequestFilter;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;

@Configuration
public class WebConfig {

    @Autowired
    private AccessTokenAuthenticationFilter accessTokenAuthenticationFilter;

    @Bean
    public FilterRegistrationBean<OncePerRequestFilter> loggingFilter() {
        FilterRegistrationBean<OncePerRequestFilter> registrationBean = new FilterRegistrationBean<>();

        registrationBean.setFilter(accessTokenAuthenticationFilter);
        // 设置过滤器应用的URL模式
        registrationBean.addUrlPatterns("/*");
        // 设置过滤器顺序
        registrationBean.setOrder(1);
        // 排除不需要过滤的路径
        return registrationBean;
    }
}